/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */

package com.hopes.bizz.basic.safe.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopes.bizz.basic.safe.entity.BaseLicenceProductionHandleRecordEntity;
import com.hopes.bizz.basic.safe.service.BaseLicenceProductionHandleRecordService;
import com.hopes.boss.common.core.util.R;
import com.hopes.boss.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 安全生产许可证处理记录
 *
 * @author pig
 * @date 2024-02-01 18:28:19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/licenceProductionHandleRecord" )
@Tag(description = "licenceProductionHandleRecord" , name = "安全生产许可证处理记录管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BaseLicenceProductionHandleRecordController {

    private final BaseLicenceProductionHandleRecordService baseLicenceProductionHandleRecordService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param baseLicenceProductionHandleRecord 安全生产许可证处理记录
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('safe_licenceProductionHandleRecord_view')" )
    public R getbaseLicenceProductionHandleRecordPage(Page page, BaseLicenceProductionHandleRecordEntity baseLicenceProductionHandleRecord) {
        LambdaQueryWrapper<BaseLicenceProductionHandleRecordEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtil.isNotNull(baseLicenceProductionHandleRecord.getBusinessId()),BaseLicenceProductionHandleRecordEntity::getBusinessId,baseLicenceProductionHandleRecord.getBusinessId());
        return R.ok(baseLicenceProductionHandleRecordService.page(page, wrapper));
    }


    /**
     * 通过id查询安全生产许可证处理记录
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('safe_licenceProductionHandleRecord_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(baseLicenceProductionHandleRecordService.getById(id));
    }

    /**
     * 新增安全生产许可证处理记录
     * @param baseLicenceProductionHandleRecord 安全生产许可证处理记录
     * @return R
     */
    @Operation(summary = "新增安全生产许可证处理记录" , description = "新增安全生产许可证处理记录" )
    @SysLog("新增安全生产许可证处理记录" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('safe_licenceProductionHandleRecord_add')" )
    public R save(@RequestBody BaseLicenceProductionHandleRecordEntity baseLicenceProductionHandleRecord) {
        return R.ok(baseLicenceProductionHandleRecordService.save(baseLicenceProductionHandleRecord));
    }

    /**
     * 修改安全生产许可证处理记录
     * @param baseLicenceProductionHandleRecord 安全生产许可证处理记录
     * @return R
     */
    @Operation(summary = "修改安全生产许可证处理记录" , description = "修改安全生产许可证处理记录" )
    @SysLog("修改安全生产许可证处理记录" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('safe_licenceProductionHandleRecord_edit')" )
    public R updateById(@RequestBody BaseLicenceProductionHandleRecordEntity baseLicenceProductionHandleRecord) {
        return R.ok(baseLicenceProductionHandleRecordService.updateById(baseLicenceProductionHandleRecord));
    }

    /**
     * 通过id删除安全生产许可证处理记录
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除安全生产许可证处理记录" , description = "通过id删除安全生产许可证处理记录" )
    @SysLog("通过id删除安全生产许可证处理记录" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('safe_licenceProductionHandleRecord_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(baseLicenceProductionHandleRecordService.removeBatchByIds(CollUtil.toList(ids)));
    }

}
